import type { Operation } from "/@/api/aiot/menu/models";
import type { AiotSubApp } from "/@/base/data";
import type { TreeDataItem } from "/@/utils/treeData";

export enum RoleType {
  // SYSTEM_ADMIN = "SYSTEM_ADMIN",
  // TENANT_ADMIN = "TENANT_ADMIN",
  project = "PROJECT_ADMIN",
  operation = "OPERATION",
  other = "NORMAL",
  platform = "SYSTEM_NORMAL",
}

export enum AdminRoleType {
  system = "SYSTEM_ADMIN",
  tenant = "TENANT_ADMIN",
}

export interface RoleItem {
  roleId?: string;
  roleName?: string;
  roleType?: RoleType | AdminRoleType;
  roleDescription?: string;
  rolePermissions?: string;
  applicationPermissions?: AiotSubApp[];
  disableOper?: boolean;
  isSystem?: boolean;
}

export interface RoleSearchModel {
  roleName: string;
}

export enum OperPermissionType {
  MANAGE = "admin",
  CHECK = "search",
}

export type AddRoleParams = AuthorizedRoleFunctionsParams &
  UpdateRoleParams & {
    roleUsers: string[];
    applicationPermissions: AiotSubApp[];
  };

export interface UpdateRoleParams {
  roleId?: string;
  roleDescription?: string;
  roleName?: string;
  roleType?: RoleType | AdminRoleType;
}

export interface AuthorizedRoleFunctionsParams {
  roleId?: string;
  roleFolderPermissions:
    | null
    | {
        applicationId: string;
        functionId: string;
      }[];
  roleMenuPermissions:
    | null
    | {
        applicationId: string;
        functionId: string;
        operationType: OperPermissionType;
      }[];
  applicationPermissions?: AiotSubApp[];
}

export interface AuthorizedRoleUsersParams {
  roleId?: string;
  usersList: string[];
}

export interface RoleUserItem {
  avatar: string;
  companyShortName: string;
  companyId: string;
  userId: string;
  userName: string;
  isSystem: boolean;
}

export interface RoleFunctionMenuItem {
  isFolder?: boolean;
  applicationId?: string;
  functionId?: string;
  //后端手误加了s，先这样
  operationsType?: OperPermissionType | null;
  operationType?: OperPermissionType | null;
  operations?: Operation[];
}

// export type OrgUserTreeItem = TreeDataItem<{
//   id: string;
//   name: string;
//   type: "ORG" | "USER";
//   checkable?: boolean;
//   orgName?: string;
// }>;

export interface OrgUserTreeItem {
  key: string;
  id: string;
  name: string;
  type: "ORG" | "USER";
  companyShortName?: string;
  companyId?: string;
  orgName?: string;
  children?: OrgUserTreeItem[];
  checkable?: boolean;
  transfterable?: boolean;
  isLeaf?: boolean;
  phone?: string;
  disabled?: boolean;
  disableCheckbox?: boolean;
  roleId?: string;
  roleName?: string;
  isSystem?: number;
  userId?: string;
}
